/* ex: set tabstop=4 shiftwidth=4 expandtab: */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>

#include <sys/stat.h>
#include <fcntl.h>


#include "crypto.h"
#include "rtsp.h"
#include "rtp.h"
#include "event.h"

#include "rtp_types.h"

#define push_hdr(__buf, __type) ((__type *) (((char *) (__buf)) - sizeof(__type)))


static void
rtp_play(int fd)
{
}

/* read packets from lfxmsg_pcap output */

typedef struct {
    int tag;
    int len;
} avdata_hdr_t;

static
void pcap_play(int fd)
{
	char pkt[2048] = {0};
    avdata_hdr_t av;
	FILE *fp;

    rtp_channel_t *ch;
    rtp_hdr_t *rtph;
    video_hdr_t *vh;
    audio_hdr_t *ah;


	if (!(fp = fopen("avdata.raw", "rb")))
		return;

again:
    if (fread(&av, sizeof(avdata_hdr_t), 1, fp) != 1)
        return;
    if (fread(pkt, av.len, 1, fp) != 1)
        return;
    ch = (void *) pkt;
    if (ch->tag != '$')
        return;
    rtph = (void *) (pkt + sizeof(rtp_channel_t));
    if (rtph->pt == 96) {
        printf("video data\n");
    } else {
        printf("audio data\n");
    }
    goto again;

	fclose(fp);
}

void
rtp_start(rtsp_session_t *sess)
{
	pcap_play(sess->chn_get->fd);
}

void
rtp_stop(rtsp_session_t *sess)
{
}

#ifdef TEST
int
main(void)
{
    pcap_play(0);
    return 0;
}
#endif
